package com.belarus.kamianiec.photo.photoSite.web.ctrl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.belarus.kamianiec.photo.photoSite.domain.Gallery;
import com.belarus.kamianiec.photo.photoSite.service.GalleryService;

//@Controller
public class GalleryController {

	private GalleryService galleryService;

	@RequestMapping("/gallery")
	public String listGallery(Map<String, Object> map) {
		map.put("gallery", new Gallery());
		map.put("galleryList", galleryService.listGallery());
		return "gallery";
	}

	@RequestMapping(value = "/galleryadd", method = RequestMethod.POST)
	public String addGallery(@ModelAttribute("gallery") Gallery gallery, BindingResult result) {
		galleryService.addGallery(gallery);
		return "redirect:/gallery";
	}

	@RequestMapping("/gallerydel/{galleryId}")
	public String deleteGallery(@PathVariable("galleryId") Integer galleryId) {
		galleryService.removeGallery(galleryId);
		return "redirect:/gallery";
	}

	public GalleryService getGalleryService() {
		return galleryService;
	}

	@Autowired
	public void setGalleryService(GalleryService galleryService) {
		this.galleryService = galleryService;
	}
}
